﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Aquaculture;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Aquaculture
{
    public class AddAquacultureCommandHandler : IRequestHandler<AddAquacultureCommand, ApiResult<int>>
    {

        private readonly IBaseRepository<AquacultureModel> _aquaculture;
        private readonly IMapper mapper;

        public AddAquacultureCommandHandler(IBaseRepository<AquacultureModel> aquaculture, IMapper mapper)
        {
            _aquaculture = aquaculture;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(AddAquacultureCommand request, CancellationToken cancellationToken)
        {
           var result=new ApiResult<int>();
            var m=mapper.Map<AquacultureModel>(request);
            m.del = 0;
            _aquaculture.Add(m);
            result.Message = "添加成功";
            result.data = 1;

            return  Task.FromResult(result);
        }
    }
}
